﻿using SIG.Data;
using SIG.Infrastructure.Cache;
using SIG.Data.UnitOfWork;
using System;
using SIG.Model.Articles;

namespace SIG.Repository
{
    public class ArticleRepository : Repository<Article>, IArticleRepository
    {
        IMainBCUnitOfWork _unitOfWork;
        private ICacheService _cacheService;
        public ArticleRepository(IMainBCUnitOfWork unitOfWork, ICacheService cacheService) : base(unitOfWork) {
            if (unitOfWork == (IMainBCUnitOfWork)null)
                throw new ArgumentNullException("unitOfWork");
            if (cacheService == (ICacheService)null)
                throw new ArgumentNullException("cacheService");
            this._unitOfWork = unitOfWork;
            this._cacheService = cacheService;
        }
     

        //public int SearchArticlesCount(int categoryId)
        //{
        //    var posts = this.;

        //    if (categoryId>0)
        //    {
        //        posts = posts.Where(l => l.CategoryId == categoryId);
        //    }

        //    var result = posts.Count();

        //    return result;
        //}

        //public IList<Article> SearchArticles(int pageIndex, int pageSize, int categoryId)
        //{
        //    var posts = this.IQueryable().Include(p=>p.Category);

        //    if (categoryId > 0)
        //    {
        //        posts = posts.Where(l => l.CategoryId == categoryId);
        //    }
            
        //    var result = posts
        //        .OrderByDescending(l => l.CreatedDate)
        //        .Skip(pageIndex * pageSize).Take(pageSize).ToList();

        //    return result;
        //}

        //public int ActiveArticlesCount(int categoryId)
        //{
        //    var posts = this.IQueryable().Where(p=>p.Active);

        //    if (categoryId > 0)
        //    {
        //        posts = posts.Where(l => l.CategoryId == categoryId);
        //    }

        //    var result = posts.Count();

        //    return result;
        //}

        //public IList<Article> GetActiveArticles(int pageIndex, int pageSize, int categoryId)
        //{
        //    var posts = this.IQueryable().Where(p=>p.Active);

        //    if (categoryId > 0)
        //    {
        //        posts = posts.Where(l => l.CategoryId == categoryId);
        //    }

        //    var result = posts
        //        .OrderByDescending(l => l.CreatedDate)
        //        .Skip(pageIndex * pageSize).Take(pageSize).ToList();

        //    return result;
        //}

    }
}
